package com.dengc.service.impl;

import com.dengc.mapper.GoodsSupplierMapper;
import com.dengc.pojo.GoodsSupplier;
import com.dengc.pojo.SysUser;
import com.dengc.service.GoodsSupplierService;
import com.dengc.utils.Contants;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("GoodsSupplierService")
public class GoodsSupplierServiceImpl implements GoodsSupplierService {

    @Autowired
    GoodsSupplierMapper goodsSupplierMapper;

    //查询所有的供货商编号信息
    @Override
    public List<GoodsSupplier> getAllSuppliercode() {
        return goodsSupplierMapper.getGoodsSupplierByCondition(new GoodsSupplier());
    }

    //分页功能实现
    @Override
    public PageInfo<GoodsSupplier> getGoodsSupplierByPage(GoodsSupplier goodsSupplier, int pageNum) {
        //开启分页
        PageHelper.startPage(pageNum, Contants.PAGESIZE);
        //分页好的数据保存起来
        List<GoodsSupplier> list = goodsSupplierMapper.getGoodsSupplierByCondition(goodsSupplier);
        return new PageInfo<>(list);
    }

    //添加供货商信息
    @Override
    public int addSupplier(GoodsSupplier goodsSupplier) {
        return goodsSupplierMapper.addSupplier(goodsSupplier);
    }

    //根据id查询供货商信息
    @Override
    public GoodsSupplier getAllGoodsById(Integer id) {
        GoodsSupplier goodsSupplier = new GoodsSupplier();
        goodsSupplier.setId(id);
        List<GoodsSupplier> list = goodsSupplierMapper.getGoodsSupplierByCondition(goodsSupplier);
        return list.get(0);
    }

    //修改供货商信息功能实现
    @Override
    public int updateSupplier(GoodsSupplier goodsSupplier) {
        return goodsSupplierMapper.updateSupplier(goodsSupplier);
    }

    //删除供货商信息功能实现
    @Override
    public int deletSupplier(Integer id) {
        return goodsSupplierMapper.deletSupplier(id);
    }
}
